package com.ddwl.wallet.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.wallet.ShopChannelAddBo;
import com.ddwl.schema.bo.wallet.WithdrawChannelAddBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.wallet.WithdrawChannelVo;
import com.ddwl.wallet.service.WithdrawChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "提现渠道相关接口")
@RestController
@RequestMapping("WithdrawChannel")
public class WithdrawChannelController extends BaseController {

    @Resource
    private WithdrawChannelService withdrawChannelService;

    /**
     * 查询用户的提款渠道
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询用户的提现渠道")
    @GetMapping("/{userId}")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO})
    public RestVo<List<WithdrawChannelVo>> queryUserWithdrawChannel(@PathVariable String userId) {
        return RestVo.ok(withdrawChannelService.queryUserChannel(userId));
    }


    @ApiOperation(value = "删除用户提现渠道")
    @DeleteMapping("/{userId}/{id}")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO})
    public RestVo<List<WithdrawChannelVo>> deleteUserChannel(@PathVariable("userId") String userId, @PathVariable("id") String id) {
        withdrawChannelService.deleteUserChannel(id, userId);
        return RestVo.ok();
    }

    @ApiOperation(value = "新增或变更用户提现渠道")
    @PutMapping("/{userId}")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO})
    public RestVo<List<WithdrawChannelVo>> setWithdrawChannel(@PathVariable("userId") String userId, @Valid @RequestBody WithdrawChannelAddBo bo) {
        bo.setUserId(userId);
        withdrawChannelService.withdrawChannelAdd(bo);
        return RestVo.ok();
    }

    @ApiOperation(value = "新增或变更用户提现渠道")
    @PostMapping("/fenxiaoChannel")
    @Auth(product = {BaseEnum.ProductEnum.API})
    public RestVo fenxiaoWithdrawChannel(@Valid @RequestBody WithdrawChannelAddBo bo) {
        withdrawChannelService.withdrawChannelAdd(bo);
        return RestVo.ok();
    }

    @ApiOperation(value = "商家后台新增或变更用户提现渠道")
    @PostMapping("/shopChannel")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo shopWithdrawChannel(@Valid @RequestBody ShopChannelAddBo bo) {
        bo.setShopId(getShopId());
        bo.setUserId(getUserId());
        bo.setType(2);
        withdrawChannelService.addShopBankCard(bo);
        return RestVo.ok();
    }

    @ApiOperation(value = "查询用户银行卡信息")
    @GetMapping("/getUserBankCard/{bankNumber}")
    @Auth(product = {BaseEnum.ProductEnum.API})
    public RestVo<WithdrawChannelVo> getUserBankCard(@PathVariable("bankNumber") String bankNumber) {
        WithdrawChannelVo vos = withdrawChannelService.getUserBankCard(bankNumber);
        return RestVo.ok(vos);
    }


}
